/*
 * 活动列表
 * @author 曾文
 * @time 2018/10/19
 * @since 1.0.0
 * */

import React from 'react'
import { connect } from 'dva'

import { Form, Select, Input, DatePicker, Button, Popconfirm } from 'antd'
import moment from 'moment';
const { RangePicker } = DatePicker;
const dateFormat = 'YYYY/MM/DD';

import { Link, hashHistory } from 'dva/router'

import config from 'config/config'

import { mapStateToProps } from 'utils/view_utils'

import styles from './activityListStyle.less'

import ListPage from 'widget/PageTmpl/ListPage'
import cx from 'classnames'

//权限管理
import FlagBtn from 'widget/FlagBtn/FlagView'

const Option = Select.Option;

const View = function ({ dispatch, model, form }) {

  const { resetFields, getFieldDecorator, validateFields, setFieldsValue } = form
  const { modelObj, namespace } = model
  let { areaList } = modelObj
  // 资讯详情页跳转
  function detailSkip(type, id = '') {
    hashHistory.push({
      pathname: '/home/activityAdmin/activityDetail',
      query: { type, id }
    });
  }
  let pageProps = {
    ui: {
      "api_url": "admin/activity/activityList",
      "method": "POST",
      "app": "",
      "params": "",
      // "mockData": mockData,
      "mockData": null,
      search_bar: {
        fields: [
          {
            en_name: 'title',
            zh_name: '活动标题',
            elem_type: 'Input',
            elem_valid_type: 'string',
          },
          {
            en_name: 'province',
            zh_name: '城市',
            elem_type: 'Cascader',
            elem_valid_type: 'string',
            changeOnSelect: false,
            cmpt_items: areaList,
						split_keys: ['province', 'city'],
						//关联的更改的搜索字段
						related_key: 'productId',
						//请求地址
						related_req_url: 'admin/estate/list',
						//默认请求
						related_req_param: {
							pageNo: 1,
							pageSize: 1000
						}
          },
          {
            en_name: 'productId',
            zh_name: '项目名称',
            elem_type: 'Select',
            elem_valid_type: 'string',
            cmpt_items: []
          },

        ],
        searchHandler: (e) => { // 自定义搜索按钮回调函数，点击搜索时触发
          console.log('search click', e)
        },
        resetHandler: () => { // 自定义重置按钮回调函数，点击重置时触发
          console.log('reset click')
        },
        searchCallback: params => { // 自定义搜索完成后的后调函数, 搜索完成后触发, 并将本次搜索的参数传入
          console.log('search finish', params)
        },
        pasteTargetList: [  // 列表组件中将输入框的en_name作为默认id(也可以通过id另外设置)
          'carName',  // 将需要粘贴事件拦截的输入框id以数组的形式传入, 该参数对应PasteFromClipboard组件的targetList参数
        ]
      },

      action_bar: [],
      // 数据表格
      "table":
      {
        "status_params": "status=0",
        "status_text": "全部",
        "scroll": { x: 1000 },
        "fields": [
          // {
          //   "en_name": "serialNumber",
          //   "zh_name": "活动编号编号",
          // },
          {
            "en_name": "title",
            "zh_name": "活动标题",
          },
          {
            "en_name": "idCardNo",
            "zh_name": "活动日期",
            width:350,
            render: (a, item, index, d, e, f) => {
              return `${item.startDate||''}${item.endDate&&' ~ '||''}${item.endDate||''}`
            },
          },
          {
            "en_name": "businessName",
            "zh_name": "所属项目",
          },
          {
            "en_name": "cityName",
            width:150,
            "zh_name": "所属城市",
              render: (text, item, index) => {
                  return `${item.provinceName||''}${item.provinceName&&item.cityName&&' - '||' '}${item.cityName||''}`
              }
          },
          {
            "en_name": "applyCnt",
            "zh_name": "报名人数",
          },

          {
            "en_name": "edit",
            "zh_name": "操作",
            render: (a, item, index, d, e, f) => {
              return (
                <span>
                   <FlagBtn node={<a onClick={() => detailSkip('edit', item.contentId)}>查看</a>} btnId={'140101'}> </FlagBtn>
                  {/* <a onClick={() => detailSkip('edit', item.contentId)}>查看</a> */}
                </span>
              )
            },
          },
        ]
      },
    },
  }
  if (!!modelObj.biz) {
		pageProps.biz = modelObj.biz
		pageProps.biz.syncBackCbf = (biz) => {
      console.log(biz)
			dispatch({
				type: `${namespace}/updateStore`,
				payload: { biz }
			})
		}
	}
  return (
    <div className={cx('pageLayout')}>
      <ListPage pageProps={pageProps} />
    </div>
  )
}

export default connect(mapStateToProps)(Form.create()(View))
